﻿// See https://aka.ms/new-console-template for more information
// Microsoft.Extensions.Configuration
// Microsoft.Extensions.Configuration.FileExtensions
// Microsoft.Extensions.Configuration.Json


using Hsp.Media.Model.Utility;
using Microsoft.Extensions.Configuration;
using SqlSugar;

Console.WriteLine("Hello, SqlSugar!");
Console.WriteLine("*********************************************");
Console.WriteLine("");

IConfigurationRoot _configuration = new ConfigurationBuilder()
    .SetBasePath(Directory.GetCurrentDirectory())
    .AddJsonFile("appsettings.json", optional: false, reloadOnChange: true)
    .Build();

var sqlConnectionString = ConfigurationExtensions.GetConnectionString(_configuration, "MediaConnection");

//Creaate database object
SqlSugarClient db = new(new ConnectionConfig() { ConfigId = "0", DbType = DbType.SqlServer, ConnectionString = sqlConnectionString, IsAutoCloseConnection = true });

//用来打印Sql方便你调式    
db.Aop.OnLogExecuting = (sql, pars) =>
{
    Console.WriteLine(sql + "\r\n" +
    db.Utilities.SerializeObject(pars.ToDictionary(it => it.ParameterName, it => it.Value)));
    Console.WriteLine();
};


{
    //// 6.格式化类名和属性名
    //foreach (var item in db.DbMaintenance.GetTableInfoList())
    //{
    //    string entityName = item.Name.Replace("_", "");/*实体名驼峰*/
    //    db.MappingTables.Add(entityName, item.Name);
    //    foreach (var col in db.DbMaintenance.GetColumnInfosByTableName(item.Name))
    //    {
    //        db.MappingColumns.Add(EntityHelper.GetEntityName(col.DbColumnName) /*类的属性驼峰*/, col.DbColumnName, entityName);
    //        Console.Write(".");
    //    }
    //}

    //db.DbFirst.IsCreateAttribute().CreateClassFile(@"D:\Codes\Hsp.WebNovels\Hsp.Media.Model\Models", "Hsp.Media.Model.Models");
}

{
    //TimeSpan ts = (TimeSpan.Parse("00:00:04.120"));//.ToString(@"HH:mm:mm,fff");

    //string ddd = ts.ToString(@"HH:mm:mm,fff");
    //Console.WriteLine(ddd);
}







Console.WriteLine("");
Console.WriteLine("*********************************************");
Console.WriteLine("Bye, SqlSugar!");
Console.ReadKey();